package com.example.project;

import java.util.ArrayList;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;


import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;


public class MapItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	
	ArrayList<OverlayItem> mOverlays=new ArrayList<OverlayItem>();
	Context mContext;

	public MapItemizedOverlay(Drawable defaultMarker) {
		  super(boundCenterBottom(defaultMarker));
	}
	
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	
	@Override
	protected OverlayItem createItem(int i) {
	  return mOverlays.get(i);
	}
	
	@Override
	public int size() {
	  return mOverlays.size();
	}
	
	public MapItemizedOverlay(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  mContext = context;
		}
	
	@Override
	protected boolean onTap(int index) {
	  OverlayItem item = mOverlays.get(index);
	  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
	  dialog.setTitle(item.getTitle());
	  dialog.setMessage(item.getSnippet());
	  dialog.setIcon(R.drawable.tobi); 
	  LayoutInflater inflater =  (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	  View v = inflater.inflate(R.layout.botonesitemized 
	          , null);
	  
	  v.setTag("679379262" +"/" + Menjar.restaurantsList.get(index).get(Menjar.KEY_ID));
	 /**TODO: Add proper telephones**/
	  
	  dialog.setView(v); 
	  
	  
	 // dialog.show(); 
	  /*dialog.setPositiveButton("Carta", new DialogInterface.OnClickListener() {

		  public void onClick(DialogInterface arg0, int arg1) {
			  
			    Intent it = new Intent(mContext, Carta.class);
		        //it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
		        mContext.startActivity(it); 
		  }});
		dialog.setNegativeButton("Truca", new DialogInterface.OnClickListener() {
		       
		  public void onClick(DialogInterface arg0, int arg1) {
			  call("973462085");
		  }});
		
		dialog.setNeutralButton("Valoracions", new DialogInterface.OnClickListener() {
		       
			  public void onClick(DialogInterface arg0, int arg1) {
				  Intent it = new Intent(mContext, FormulariValoracions.class);
			        //it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
			        mContext.startActivity(it); 
			  }});
		
		dialog.setNeutralButton("Valora", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface arg0, int arg1) {
				  Intent it = new Intent(mContext, FormulariValoracions_IntroDades.class);
			        //it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
			        mContext.startActivity(it); 
			  }});
			
		*/
	  dialog.show();
	  return true;
	}
	
	
}

